package com.assignment.main;

import com.assignment.database.DBOperations;
import com.assignment.gui.EditSupplierScreen;
import com.assignment.gui.SearchScreen;
import com.assignment.gui.ViewSupplierScreen;

/**
 * 
 * 
 * Class to create objects from the underlying database table Supplier, which
 * can then be manipulated within java and inserted back into the database.
 * 
 * @author John Wright and Luke Williams
 * 
 * @version 1.0
 */
public class Supplier implements Selectable {

	private String id, name, collection, address;

	/**
	 * Constructor method which takes a String array, from which initial values
	 * are set.
	 * 
	 * @param data
	 *            Array of Item attributes
	 */
	public Supplier(String[] data) {
		if (data[0] != null)
			id = data[0].replaceAll("\n", "").trim();
		name = data[1];
		collection = data[2];
		address = data[3];
	}

	

	/**
	 * Method to get the id of the supplier.
	 * 
	 * @return id the Item id
	 */
	public String getId() {
		return id;
	}

	/**
	 * Method to set the id of an supplier.
	 * 
	 * @param id
	 *            The Item id
	 * 
	 * 
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * Method to get the name of an item
	 * 
	 * @return name The item name
	 * 
	 *         .
	 */
	public String getName() {
		return name;
	}

	/**
	 * Method to set the name of an item.
	 * 
	 * @param name
	 *            The item name
	 * 
	 * 
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 
	 * Method to get the collection the supplier belongs to
	 * 
	 * @return collection The supplier collection
	 * 
	 */
	public String getCollection() {
		return collection;
	}

	/**
	 * 
	 * Method to set the collection the supplier belongs to
	 * 
	 * @param collection
	 *            The supplier collection
	 * 
	 */
	public void setCollection(String collection) {
		this.collection = collection;
	}

	/**
	 * Method to get the address of the supplier
	 * 
	 * @return address The supplier address
	 * 
	 * 
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * Method to get the address of the supplier
	 * 
	 * @param address
	 *            The supplier address
	 * 
	 * 
	 */
	
	/**
	 * Override of the toString() method in the object class, to show the name
	 * and type of the supplier when it is added to a JList object in the
	 * SearchScreen
	 * 
	 * @return A String representation of the item
	 */
	@Override
	public String toString() {
		return "Supplier: " + name;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.assignment.main.Selectable#onSelectToView(com.assignment.gui.SearchScreen
	 * )
	 */
	@Override
	public void onSelectToView(SearchScreen screen) {
		new ViewSupplierScreen(this, screen);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.assignment.main.Selectable#onSelectToEdit(com.assignment.gui.SearchScreen
	 * )
	 */
	@Override
	public void onSelectToEdit(SearchScreen screen) {
		new EditSupplierScreen(this, screen);

	}
	
	
	
	public void setAddress(String address) {
		this.address = address;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.assignment.main.Selectable#onSelectToDelete()
	 */
	@Override
	public void onSelectToDelete() {
		DBOperations.deleteSupplier(this);

	}

}
